import { Configuration, App } from '@midwayjs/decorator';
import * as swagger from '@midwayjs/swagger';
import * as jwt from '@midwayjs/jwt';
import * as koa from '@midwayjs/koa';
import * as socketio from '@midwayjs/socketio';
import * as validate from '@midwayjs/validate';
import * as info from '@midwayjs/info';
import { join } from 'path';
import * as orm from '@midwayjs/typeorm';
import * as bull from '@midwayjs/bull';
import * as oss from '@midwayjs/oss';
// import { DefaultErrorFilter } from './filter/default.filter';
// import { NotFoundFilter } from './filter/notfound.filter';
import { ReportMiddleware } from './middleware/report.middleware';
import * as redis from '@midwayjs/redis';
import * as crossDomain from '@midwayjs/cross-domain';

@Configuration({
  imports: [
    oss,
    koa,
    socketio,
    // swagger,
    jwt,
    bull,
    redis,
    crossDomain,
    orm,
    {

      component: swagger,
      // enabledEnvironment: ['local']
    },
    validate, //api 传参的校验   dto  前端 发送的接口 的参数校验  , 跟 swagger 做配合
    {
      component: info,
      enabledEnvironment: ['local'],
    },
  ],
  importConfigs: [join(__dirname, './config')],
})
export class ContainerLifeCycle {
  @App()
  app: koa.Application;

  async onReady() {
    // add middleware
    this.app.useMiddleware([ReportMiddleware]); // 注册一个中间件
    // add filter
    // this.app.useFilter([NotFoundFilter, DefaultErrorFilter]);
  }
}

console.log("http://127.0.0.1:6001/swagger-ui/index.html");
